import axios from 'axios';
import Cookies from 'js-cookie';
import qs from 'qs';
import API from 'api/api';

/*
 用户登录接口
 【入参】
 */
export async function login(params = {}) {
  try {
    let res = await axios.post(API.login, qs.stringify(params)),
        data = res.data,
        token = data.token
    if (data.code === 0) {
        Cookies.set('token', token || 'testToken')
        return 'success'
    } else {
      return `login error: , ${res.message}`
    }

  } catch (e) {
    throw new Error('API Error Message: ', e)
  }
}
